package com.itheima.api.calendar;

import java.util.Calendar;

public class CalenderDemo {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        getDate(cal);

        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        int secnd = cal.get(Calendar.SECOND);
        System.out.println(hour + ":" + minute + ":" + secnd);

        //国际对于星期的认定为从周日开始到周六结束,为符合阅读习惯可以将其存入数组
        int week = cal.get(Calendar.DAY_OF_WEEK) -1;
        String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
        System.out.println(weeks[week]);
    }

    public static void getDate(Calendar cal) {
        //System.out.println("cal = " + cal);
        int year = cal.get(Calendar.YEAR);
        //外国标准月从零开始(0代表1月 11代表12月) ,因此为了符合阅读习惯可以将月份加一
        int month = cal.get(Calendar.MONTH) + 1;
        int day = cal.get(Calendar.DAY_OF_MONTH);
        System.out.println(year + "年" + month + "月" + day + "日");
    }
}
